/**
 * Created with IntelliJ IDEA.
 * Description:队列单链表实现 尾结点入队 头结点出队 时间复杂度O(1)
 * User: lenovo
 * Date: 2022-08-16
 * Time: 11:44
 */
public class MyQueue {
    //创建节点
    static class Node{
        int data;
        Node next;
        public Node(int data){
            this.data = data;
        }
    }
    //头结点:入队
    private Node head;
    //尾结点:出队
    private Node tail;
/**
 * 入队
 */
public void  offer(int data){
    Node node = new Node(data);
    //空队列
    if(head == null){
        head = node;
        tail = node;
    }else {
        tail.next = node;
        tail=node;
    }
}
/**
 * 出队
 */
public int poll(){
    //空节点
    if(head == null){
        return -1;
    }//只有一个节点
    int tmp = head.data;
    if(head.next == null){
        head = null;
        tail = null;
    }else {
        head=head.next;
    }
    return tmp;
}
/**
 * peek
 */
public int peek(){
    //空节点
    if(head == null){
        return -1;
    }//只有一个节点

    return head.data;
}

}
